<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/common.jspf"%>
<%@ include file="/common/taglibs.jspf"%>
<html lang="en">
<head>
<title><s:message code="login.ui.title" /></title>
</head>
<body>
	<div>
		<c:if test="${empty tenantConfig }">
			<div class="alert">
				<strong><s:message code="tenantConfig.error.empty"></s:message></strong>
			</div>
		</c:if>
		<div class="btn-toolbar">
			<button class="btn" onclick="activateTenant();">
				<s:message code="tenant.func.activate" />(仅做测试)
			</button>
			<button class="btn" onclick="upgradeTenant();">
				<s:message code="tenant.func.upgrade" />(仅做测试)
			</button>
			<button class="btn btn-warning" onclick="lockTenant();">
				<s:message code="tenant.func.lock" />
			</button>
			<button class="btn btn-danger" onclick="deactivateTenant();">
				<s:message code="tenant.func.deactivate" />
			</button>

		</div>
		<ul class="nav nav-tabs">
			<li class="active"><a href="#summary" data-toggle="tab"><s:message code="tenant.ui.tab.summary" /></a></li>
			<li><a href="#conf" data-toggle="tab"><s:message code="tenant.ui.tab.conf" /></a></li>
		</ul>

		<div class="tab-content ">
			<div class="tab-pane active" id="summary">
				<form id="basic-form" action="index.do" method="GET" class="form-horizontal">
					<fieldset>
						<div class="control-group">
							<label class="control-label visible-ie8 visible-ie9"><s:message code='tenant.tenantCode' /></label>
							<div class="controls">
								<input type="text" name="tenantCode" value='<c:out value="${tenant.tenantCode }"/>' readonly="readonly" />
							</div>
						</div>
						<div class="control-group">
							<label class="control-label visible-ie8 visible-ie9"><s:message code='tenant.tenantAlias' /></label>
							<div class="controls">
								<input type="text" name="tenantAlias" value='<c:out value="${tenant.tenantAlias }"/>' readonly="readonly" />
							</div>
						</div>
						<div class="control-group">
							<label class="control-label visible-ie8 visible-ie9"><s:message code='tenant.status' /></label>
							<div class="controls">
								<input type="text" name="status" value='<s:message code="tenant.status.${tenant.status }"/>' readonly="readonly" />
							</div>
						</div>
						<div class="control-group">
							<label class="control-label visible-ie8 visible-ie9"><s:message code='tenant.createBy' /></label>
							<div class="controls">
								<input type="text" name="createUserId" value='<c:out value="${li:getUser(tenant.createBy).userName }"/>' readonly="readonly" />
							</div>
						</div>
						<div class="control-group">
							<label class="control-label visible-ie8 visible-ie9"><s:message code='tenant.createDatetime' /></label>
							<div class="controls">
								<input type="text" name="createDatetime" value='<c:out value="${li:formatDateTime(tenant.createDatetime) }"/>' readonly="readonly" />
							</div>
						</div>
						<div class="control-group">
							<label class="control-label visible-ie8 visible-ie9"><s:message code='tenant.maxMembers' /></label>
							<div class="controls">
								<input type="text" name="maxMembers" value='<c:out value="${tenant.maxMembers }"/>' readonly="readonly" /> &nbsp;
								<button type="button" class="btn btn-primary">
									<s:message code="tenant.func.upgrade" />
								</button>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label visible-ie8 visible-ie9"><s:message code='tenant.maxStorage' /></label>
							<div class="controls">
								<input type="text" name="maxStorage" value='<c:out value="${tenant.maxStorage }"/> (GB)' readonly="readonly" /> &nbsp;
								<button type="button" class="btn btn-primary">
									<s:message code="tenant.func.upgrade" />
								</button>
							</div>
						</div>
						<div class="control-group">
							<label class="control-label visible-ie8 visible-ie9"><s:message code='tenant.trialDays' /></label>
							<div class="controls">
								<input type="text" name="trialDays" value='<c:out value="${tenant.trialDays }"/>' readonly="readonly" />
							</div>
						</div>
						<div class="control-group">
							<label class="control-label visible-ie8 visible-ie9"><s:message code='tenant.expiredDate' /></label>
							<div class="controls">
								<input type="text" name="expiredDate" value='<c:out value="${li:formatDate(tenant.expiredDate) }"/>' readonly="readonly" /> &nbsp;
								<button type="button" class="btn btn-primary" onclick="renewTenant();">
									<s:message code="tenant.func.recharge" />
								</button>
								&nbsp;
								<button type="button" class="btn btn-primary">
									<s:message code="tenant.func.upgrade" />
								</button>
							</div>
						</div>
					</fieldset>
				</form>
			</div>
			<div class="tab-pane" id="conf">
				<form id="conf-form" action="config.json" method="POST"
					class="form-horizontal">
					<fieldset>
						<div class="control-group">
							<label class="control-label"><s:message code='tenant.tenantAlias' /></label>
							<div class="controls">
								<input type="text" id="tenantAlias" name="tenantAlias" value='<c:out value="${tenant.tenantAlias }"/>' />
							</div>
						</div>
					</fieldset>
					<c:forEach items="${metaAttrGroups }" var="metaAttrGroup">
						<fieldset>
							<legend>
								<s:message code='tenantConfig.${metaAttrGroup.code }' />
							</legend>
							<c:forEach items="${metaAttrGroup.attrList }" var="metaAttr">
								<c:set var="attrValue" value="${metaAttr.defaultValue }"></c:set>
								<c:if test="${not empty APP_TENANT_CONFIG[tenant.id].confInfoMap[metaAttrGroup.code][metaAttr.key] }">
									<c:set var="attrValue" value='${APP_TENANT_CONFIG[tenant.id].confInfoMap[metaAttrGroup.code][metaAttr.key] }'></c:set>
								</c:if>
								<div class="control-group">
									<label class="control-label"><s:message code='tenantConfig.${metaAttrGroup.code }.${metaAttr.key }' /></label>
									<div class="controls">
										<input type="text" id="${metaAttrGroup.code }_${metaAttr.key }" name="${metaAttrGroup.code }_${metaAttr.key }" value='<c:out value="${attrValue }"/>' />
									</div>
								</div>
							</c:forEach>
						</fieldset>
					</c:forEach>
					<div class="form-actions">
						<button type="submit" class="btn btn-primary" data-loading-text="<s:message code='common.processing' />">
							<i class="icon-ok"></i>
							<s:message code="btn.submit" />
						</button>
					</div>
				</form>
			</div>
		</div>
	</div>
	<div class="form-actions" style="text-align: center;">
		<button type="button" class="btn" onclick="history.back();">
			<s:message code="btn.back" />
		</button>
	</div>
	<script type="text/javascript">
		$(document).ready(function(){	
			$('#conf-form').littFormSubmit({		
				rules : {
					tenantAlias: {
		                required: true,
		                minlength: 4,
		                maxlength: 50
		            }
				},	
				success: function(reply){			
					$.webtools.alert({
					  containerId: "conf-form"
					  ,type: "success",
						overwrite: false,
						position: "prepend",
						message: "<s:message code='tenant.func.conf.success' />"				
					}); 				
				}
			});
			
		});	
		
			
		function activateTenant(){
			location.href = "${contextPath }/login/activateTenant.do";
		}
		
		function upgradeTenant(){
			location.href = "${contextPath }/login/upgradeTenantPermission.do";		
		}
		
		function lockTenant(){
			bootbox.confirm("<s:message code='tenant.func.lock.confirm' />", function(result){
				if(result)
				{
					$.webtools.ajax({
						url: "${contextPath }/login/lockTenant.json",
						params: {},
						success: function(reply) {
							location.reload();
						}
					});	
				}
			});	
		}
		
		function renewTenant(){
			location.href = "${contextPath }/mgr/tenantMgr/renewOrder.do?tenantId=${tenant.id }";
		}
		
		function deactivateTenant()
		{
			bootbox.confirm("<s:message code='tenant.func.deactivate.confirm' />", function(result){
				if(result)
				{
					$.webtools.ajax({
						url: "${contextPath }/login/deactivateTenant.json",
						params: {},
						success: function(reply) {
							location.reload();
						}
					});	
				}
			});	
		}

	</script>
</body>
</html>
